//
//  C11BonjourClient.m
//  C11BonjourClient
//
//  Created by 花强 on 2017/12/25.
//  Copyright © 2017年 花强. All rights reserved.
//

#import "C11BonjourClient.h"

@implementation C11BonjourClient

-(instancetype)init{
    if (self = [super init]) {
        _finishedLoading = NO;
        _serviceBrowser = [[NSNetServiceBrowser alloc] init];//浏览器实例
        [_serviceBrowser setDelegate:self];//浏览器实例的代理设置为当前对象
    }
    return self;
}

#pragma mark -
#pragma mark NSNetServiceBrowserDelegate methods
-(void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)browser{
    NSLog(@"Begin searching");
}

-(void)netServiceBrowser:(NSNetServiceBrowser *)browser didFindDomain:(NSString *)domainString moreComing:(BOOL)moreComing{
    
}

-(void)netServiceBrowser:(NSNetServiceBrowser *)browser didFindService:(NSNetService *)service moreComing:(BOOL)moreComing{
    NSLog(@"Find server:%@",service);
    if (!moreComing) {//条件判断：服务浏览器是否正在等待其他服务
        //没有心的服务 停止搜索
        [self.serviceBrowser stop];
    }
}

-(void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)browser{
    //停止搜索，将标记设置为退出循环运行
    NSLog(@"Stop searching");
    self.finishedLoading = YES;
}

@end
